package com.sunseagear.wind.modules.sys.json;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sunseagear.common.base.http.R;
import com.sunseagear.common.base.mvc.controller.BaseBeanController;
import com.sunseagear.common.utils.StringUtils;
import com.sunseagear.wind.common.aspectj.annotation.Log;
import com.sunseagear.wind.common.aspectj.enums.LogType;
import com.sunseagear.wind.modules.sys.entity.Organization;
import com.sunseagear.wind.modules.sys.service.impl.OrganizationServiceImpl;
import com.sunseagear.wind.common.utils.UserUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 *
 * @version V1.0
 * @package biz.partyCongress
 * @title: 组织机构控制器
 * @description: 组织机构控制器
 * @author:
 * @date: 2020-12-02 05:09:05
 * @copyright: www.sunseagear.com Inc. All rights reserved.
 */

@RestController
@RequestMapping("json/organization")
@Log(title = "组织机构")
@RequiredArgsConstructor
public class OrganizationJsonController extends BaseBeanController {

    private final OrganizationServiceImpl organizationService;

    @PostMapping("/list")
    @Log(logType = LogType.SELECT)
    public R<List<Organization>> List() {
        QueryWrapper<Organization> queryWrapper = new QueryWrapper<>();
        String tenantId = UserUtils.getTenantId();
        if (!StringUtils.isEmpty(tenantId)) {
            queryWrapper.eq("t.tenant_id", tenantId);
        }
        List<Organization> list = organizationService.selectTreeList(queryWrapper);
        return R.success(list);
    }

    @GetMapping("detail/{id}")
    @Log(logType = LogType.SELECT)
    public R<Organization> detail(@PathVariable("id") Long id) {
        Organization organization = organizationService.getById(id);
        return R.success(organization);
    }

}
